<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
// import Socket from '@/utils/webSocket.js'
// import defaultSettings from '@/settings'

export default {
  name: 'App',
  data() {
    return {
      connectWebsocket: null,
      readyState: null,
      notify: null
    }
  },
  mounted() {
    // if (!defaultSettings.isWPF && !defaultSettings.isCEF) {
    //   this.initConnectWebSocket()
    // }
  },
  methods: {
    initConnectWebSocket() {
      this.connectWebsocket = new Socket({
        url: this.$store.state.app.wsBasePath + '/webSocket/ConnectWebSocket'
      })
      this.connectWebsocket.onmessage()
      setInterval(() => {
        var readyState = this.connectWebsocket.ws.readyState
        if (this.readyState !== readyState) {
          switch (readyState) {
            case 0:
              if (this.notify !== null) {
                this.notify.close()
              }
              this.notify = this.$notify.info({
                title: '网络状态',
                message: '网络连接中...',
                duration: 0,
                showClose: false
              })
              break
            case 1:
              if (this.notify !== null) {
                this.notify.close()
                if (this.readyState !== 1) {
                  this.$notify.success({
                    title: '网络状态',
                    message: '重新连接成功!'
                  })
                }
              }
              break
            case 2:
              if (this.notify !== null) {
                this.notify.close()
              }
              this.notify = this.$notify.error({
                title: '网络状态',
                message: '网络出现中断,正在尝试重新连接...',
                duration: 0,
                showClose: false
              })
              break
            case 3:
              if (this.notify !== null) {
                this.notify.close()
              }
              this.notify = this.$notify.error({
                title: '网络状态',
                message: '无法连接到服务器!',
                duration: 0,
                showClose: true
              })
              break
            default:
              break
          }
          this.readyState = readyState
        }
      }, 1000)
    }
  }
}
</script>
